import 'dart:async';

import 'package:flutter/material.dart';
import 'package:life_milestones/MS-global-url.dart';
import 'package:life_milestones/MS-request.dart';
import 'package:life_milestones/MS-route.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:life_milestones/controller/MS-mile-stone-controller.dart';
import 'package:life_milestones/util/MS-config-info-util.dart';
import 'package:life_milestones/util/MS-database-util.dart';
import 'package:provider/provider.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'controller/MS-global-user-controller.dart';



void main() async {await ScreenUtil.ensureScreenSize();
  await MSDatabaseUtil().init();
  await MSConfigInfoUtil().init();
  MSRequest().host = MSGlobalUrl.host;
  await MSRequest().init();
  await MSGlobalUserController().init();
  runApp( MultiProvider(
    providers: [
      ChangeNotifierProvider<MSGlobalUserController>(create: (_)=>MSGlobalUserController()),
      ChangeNotifierProvider<MSMileStoneController>(create: (_)=>MSMileStoneController()),
    ],
    child: const MyApp(),
  ));
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});
  @override
  Widget build(BuildContext context) {

    return ScreenUtilInit(
        designSize: const Size(375, 812),
        minTextAdapt: true,
        splitScreenMode: true,
        builder: (_, child) {

          return MaterialApp(
            title: 'Flutter Demo',
            theme: ThemeData(
              primarySwatch: Colors.blue,
              colorScheme: ColorScheme.fromSeed( seedColor: Color(0xFF70C37A)
              ),
            ),
            localeResolutionCallback: (Locale? locale, Iterable<Locale> ls){
              MSGlobalUserController().lang = locale?.languageCode ?? "en";
            },
            debugShowCheckedModeBanner: false,
            initialRoute: "launch",
            onGenerateRoute: onGenerateRoute,
            builder: EasyLoading.init(),
          );
        });
  }
}
